<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('getSaltFile'))
{
	function getSaltFile($file = '')
	{
		return $file.'?'.filemtime(rootDir().$file);
	}
}

if ( ! function_exists('getCssLink'))
{
	function getCssLink($file = '')
	{
		return '<link href="'.base_url().getSaltFile('css/'.$file).'" rel="stylesheet" type="text/css">';
	}
}

if ( ! function_exists('getJsLink'))
{
	function getJsLink($file = '')
	{
		return '<script type="text/javascript" src="'.base_url().getSaltFile('js/'.$file).'"></script>';
	}
}

if ( ! function_exists('createPage'))
{
	function createPage($buildContent = array(), $jsLink = array(), $cssLink = array())
	{
		$CI =& get_instance();
		$content = '';
		if (count($buildContent))
		{
			foreach($buildContent as $key => $el)
				$content .= $CI->load->view($key,$el,true);
		}
		return $CI->load->view('pageCarcas',array('content' => $content,'jsLink' => $jsLink,'cssLink' => $cssLink),true);
	}
}


if ( ! function_exists('rootDir'))
{
	function rootDir()
	{
		if (!isset($rootDir))
		{
			static $rootDir;
			$rootDir = pathinfo($_SERVER['SCRIPT_FILENAME']);
			$rootDir = $rootDir['dirname'];
			$rootDir = str_replace("\\", '/', $rootDir);
			if (substr($rootDir, -1) != '/') $rootDir .= '/';
		}
		return $rootDir;
	}
}

function myMD5($s)
{ 
	return md5($s."yGFBhtfyrfyTrfby5dbY%4d^%4wc5v3SDr4wScv%$".md5($s.$s)."q&N^g");
}

function browserSecData()
{
	$secData = isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?mb_strtolower(substr(trim($_SERVER['HTTP_ACCEPT_LANGUAGE']),0,2)):'i7NG6rtfyrfybrfy4';
	$secData .= isset($_SERVER['HTTP_ACCEPT_ENCODING'])?mb_strtolower(trim($_SERVER['HTTP_ACCEPT_ENCODING'])):'bytrYBtngvuaytdgvua';
	$secData .= isset($_SERVER['HTTP_ACCEPT_CHARSET'])?mb_strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])):'KMIuukjhmnUHByGf';
	return myMD5($secData);
}

function gmtArr()
{
	$gmtArr = array
	(
		'(GMT - 12:00)'	=>	-12	*3600,
		'(GMT - 11:00)'	=>	-11	*3600,
		'(GMT - 10:00)'	=>	-10	*3600,
		'(GMT - 9:00)'	=>	-9	*3600,
		'(GMT - 8:00)'	=>	-9	*3600,
		'(GMT - 7:00)'	=>	-7	*3600,
		'(GMT - 6:00)'	=>	-6	*3600,
		'(GMT - 5:00)'	=>	-5	*3600,
		'(GMT - 4:30)'	=>	-4	*3600 - 1800,
		'(GMT - 4:00)'	=>	-4	*3600,
		'(GMT - 3:30)'	=>	-3	*3600 - 1800,
		'(GMT - 3:00)'	=>	-3	*3600,
		'(GMT - 2:00)'	=>	-2	*3600,
		'(GMT - 1:00)'	=>	-1	*3600,
		'(GMT - 0:00)'	=>	0,
		'(GMT + 1:00)'	=>	1	*3600,
		'(GMT + 2:00)'	=>	2	*3600,
		'(GMT + 3:00)'	=>	3	*3600,
		'(GMT + 3:30)'	=>	3	*3600 + 1800,
		'(GMT + 4:00)'	=>	4	*3600,
		'(GMT + 4:30)'	=>	4	*3600 + 180,
		'(GMT + 5:00)'	=>	5	*3600,
		'(GMT + 5:30)'	=>	5	*3600 + 1800,
		'(GMT + 5:45)'	=>	5	*3600 + 2700,
		'(GMT + 6:00)'	=>	6	*3600,
		'(GMT + 6:30)'	=>	6	*3600 + 1800,
		'(GMT + 7:00)'	=>	7	*3600,
		'(GMT + 8:00)'	=>	8	*3600,
		'(GMT + 9:00)'	=>	9	*3600,
		'(GMT + 9:30)'	=>	9	*3600 + 1800,
		'(GMT + 10:00)'	=>	10	*3600,
		'(GMT + 11:00)'	=>	11	*3600,
		'(GMT + 12:00)'	=>	12	*3600,
		'(GMT + 13:00)'	=>	13	*3600,
		'(GMT + 14:00)'	=>	14	*3600,
	);
	
	return $gmtArr;
}

function toTime($unixTime, $time = true)
{
	global $config;
	$gmt = gmtArr();
	
	if (!empty($_SESSION['userData']->pDiffTimeZone)) $diff = $_SESSION['userData']->pDiffTimeZone; else
	{
		if (empty($config['default_gmtDiff']) || empty($gmt[$config['default_gmtDiff']]))
			$config['default_gmtDiff'] = '(GMT + 4:00)';
		$diff = $gmt[$config['default_gmtDiff']];
	}
	
	$nTime = abs($unixTime) + $diff;
	$mNum = abs(mdate('%m', $nTime)) - 1;
	
	if ($time === 10) return mdate('%H:%i:%s', $nTime);
	if (isset($config['monthNames']) && isset($config['monthNames'][$mNum]))
		$month = $config['monthNames'][$mNum]; else $month = '#error.... function toTime($datestamp) ....error#';
		
	$return = mdate('%d ', $nTime).$month.mdate(' %Y', $nTime);
	if ($time)
		$return .= mdate(', %H:%i', $nTime);
	return $return;	
}



function setKeys($arr, $keyName)
{
	if (!is_arr($arr)) return $arr;
	$res = array();
	foreach ($arr as $val)
	{
		if (is_array($val))
		{
			if (empty($val[$keyName])) return $arr;
			$res[$val[$keyName]] = $val;
		} else if (is_object($val))
		{
			if (empty($val->$keyName)) return $arr;
			$res[$val->$keyName] = $val;
		}
	}
	return $res;
}

function printROld($arr)
{
	$export = '<pre>'.print_r($arr, true).'</pre>';
	return $export;
		
}

function extractFieldFromDataArray($dataArray, $field, $nulls = true)
{
	if (!is_array($dataArray) || !sizeof($dataArray)) return array();
	$res = array();
	
	foreach ($dataArray as $dataItem)
	{
		if (is_array($dataItem) && isset($dataItem[$field]))
		{
			if ($nulls || (abs($dataItem[$field]) != 0))
				$res[] = $dataItem[$field];
		} else if (is_object($dataItem) && isset($dataItem->$field))
		{
			if ($nulls || (abs($dataItem->$field) != 0))
				$res[] = $dataItem->$field;
		}
		
	}
	return $res;
}

function is_arr(&$arr = array())
{
	return (isset($arr) && is_array($arr) && sizeof($arr));
}

function isValidEmail($mail)
{
	$exp = '/([A-Za-z0-9_\-]+\.)*[A-Za-z0-9_\-]+@([A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]\.)+[A-Za-z]{2,4}/u';
	preg_match_all($exp, $mail, $pEmail);
	return isset($pEmail[0][0]) && !empty($pEmail[0][0]);		
}

if ( ! function_exists('setupCookie'))
{
	function setupCookie($name, $val, $time)
	{
		global $config;

		$cookie = array(
							'name'   => $name,
							'value'  => $val,
							'expire' => $time,
							'domain' => '.'.$config['cookieDomain'],
							'path'   => $config['cookiePath'],
							'prefix' => '',
							'secure' => FALSE
						);
						
		$CI = &get_instance();
		
		$CI->input->set_cookie($cookie); 
	}
}

function bbToHtml($str)
{
	$bb = array('[b]', '[/b]', '[i]', '[/i]', '[s]', '[/s]', '[u]', '[/u]',
				'[li]', '[/li]', '[ol]', '[/ol]', '[ul]', '[/ul]');

	$bb2 = array('<strong>', '</strong>', '<em>', '</em>', '<s>', '</s>', '<u>', '</u>',
				'<li>', '</li>', '<ol>', '</ol>', '<ul>', '</ul>');


	$str = str_replace($bb, $bb2, $str);

	$simple_search = array(
		'/\[url\=(.*?)\](.*?)\[\/url\]/is',
		'/\[url\](.*?)\[\/url\]/is',
		'/\[img\](.*?)\[\/img\]/is');

	$simple_replace = array(
		'<a href=$1 rel="nofollow" title="$2" target="_blank">$2</a>',
		'<a href=$1 rel="nofollow" title="$1" target="_blank">$1</a>',
		'<img src=$1>',
	);
	
	$str = preg_replace ($simple_search, $simple_replace, $str);
	$str = preg_replace('/href=&quot;(.*?)&#058;(.*?)&quot;/is', 'href="$1:$2"', trim($str));

	$str = str_replace(array("\r\n", "\n", "\r"), '<br>', $str);

	return $str;
}


function isAjax()
{
	return isset($_SERVER['HTTP_X_REQUESTED_WITH']);
}

function linkMarkItUp()
{
	return '<script type="text/javascript" src="'.base_url().'plugins/markitup/jquery.markitup.js"></script>
	<script type="text/javascript" src="'.base_url().'plugins/markitup/sets/bbcode/set.js"></script>
	<link rel="stylesheet" type="text/css" href="'.base_url().'plugins/markitup/skins/markitup/style.css">
	<link rel="stylesheet" type="text/css" href="'.base_url().'plugins/markitup/sets/bbcode/style.css">';
}

function escapeHtml($str = '')
{
	return str_replace(array('"', '<', '>'), array('&quot;', '&lt;', '&gt;'), $str);
}

function quot2apostrophe($str = '')
{
	return str_ireplace(array('"', '&amp;quot;', '&quot;'), "'", $str);
}

function checkExistEmail($table, $field, $mail)
{
	$CI =& get_instance();
	$CI->db->from($table);
	$CI->db->where($field, $mail);
	$CI->db->where('dDeleted', 0);

	return $CI->db->count_all_results();
}

function uploadImage($fileName, $originalPath, $previewPath, $removeSource = false, $prevW = 100, $prevH = 100)
{
	$res = new stdClass();
	$res->error = false;	
	
	if (!is_uploaded_file($fileName))
	{
		$res->error = '';
		return $res;	
	}
	
	$originalPath = str_replace("\\", '/', $originalPath);
	if (substr($originalPath, -1) != '/') $originalPath .= '/';
	
	$previewPath = str_replace("\\", '/', $previewPath);
	if (substr($previewPath, -1) != '/') $previewPath .= '/';
	
	$newFileName = now().'_'.random_string('alnum', 12).'.jpg';
	$formatError = 'Изображение имеет неверный формат';
	
	$fileinfo = getimagesize($fileName);
			
	$ext = false;
	switch ($fileinfo['mime'])
	{
		case 'image/jpeg':
		case 'image/jpg':
		case 'image/pjpeg': $ext = 'jpg'; break;
		case 'image/png': $ext = 'png'; break;
	}
	if (!$ext)
	{
		$res->error = 'неверный тип изображения(допустимо: jpg, png)';
		return $res;
	}
	
	switch ($ext) 
	{
		case 'png':						
			$oldImg = imagecreatefrompng($fileName);
			break;
		case 'jpg':
			$oldImg = imagecreatefromjpeg($fileName);
			break;
	}
	
	if (!$oldImg)
	{
		$res->error = $formatError.' #1';
		return $res;
	}
	
	$w = imagesx($oldImg);
	$h = imagesy($oldImg);
	
	if (!$w || !$h)
	{
		$res->error = $formatError.' #2';
		return $res;
	}
	
	$newImg = imagecreatetruecolor($w, $h);	
	if (!imagecopyresampled($newImg, $oldImg, 0, 0, 0, 0, $w, $h, $w, $h))
	{
		$res->error = 'Ошибка преобразования изображения.';
		return $res;
	}
	
	if (!imagejpeg($newImg, $originalPath.$newFileName, 73))
	{
		$res->error = 'Не удалось переместить файл #1';
		return $res;
	}

	if (!imageQuad('jpg', $originalPath.$newFileName, $previewPath.$newFileName, false, $prevW, $prevH))
	{
		$res->error = 'Не удалось переместить файл #2';
		return $res;
	}
	
	if ($removeSource) @unlink($fileName);

	$res->fileName = $newFileName;
	return $res;
}

function imageQuad($ext, $fileName, $newFileName, $ge, $sizex = false, $sizey = false)
{
	switch ($ext) 
	{
		case 'png':						
			$old = imagecreatefrompng($fileName);
			if (!$old) return false;
			break;
		case 'jpg':
			$old = imagecreatefromjpeg($fileName);
			if (!$old) return false;
			break;
	}
	
	$w = (double)imagesx($old);
	$h = (double)imagesy($old);
	$xsize = 0.0;
	$ysize = 0.0;
	$xfrom = 0.0;
	$yfrom = 0.0;
	
	if ($sizex && !$sizey)
		$sizey = $sizex;
	if (!$ge)
		$ge = $sizex/$sizey;
	
	if ($w > $h)
	{
		$xsize = $h*$ge;
		$ysize = $h;
		$xFrom =($w - $xsize)/2;
		$xTo = ($w + $xsize)/2;	
		$yFrom = 0;
		$yTo = $ysize;
		
		if ($xFrom < 0)
		{
			$xsize = $w;
			$ysize = $w/$ge;
			$xFrom = 0;
			$xTo = $xsize;
			$yFrom = ($h - $ysize)/2;
			$yTo = ($h + $ysize)/2;	
		}
	} 
	else
	{
		$xsize = $w;
		$ysize = $w/$ge;
		$xFrom = 0;
		$xTo = $w;	
		$yFrom = ($h - $ysize)/2;
		$yTo = ($h + $ysize)/2;
		if ($yFrom < 0)
		{
			$xsize = $w;
			$ysize = $w/$ge;
			$xFrom = 0;
			$xTo = $xsize;
			$yFrom = ($h - $ysize)/2;
			$yTo = ($h + $ysize)/2;	
		}
	}	
	
	if ($sizex && $sizey)
	{
		$new = imagecreatetruecolor($sizex, $sizey);
		imagecopyresampled($new, $old, 0, 0, $xFrom, $yFrom, $sizex, $sizey, $xsize, $ysize);
	}
	else
	{
		$new = imagecreatetruecolor($xsize, $ysize);
		if (!imagecopy(
						$new,	//resource dst_im
						$old,	//resource src_im
						0,		//int dst_x
						0,		//int dst_y
						$xFrom,	//int src_x
						$yFrom,	//int src_y
						$xsize,	//int src_w
						$ysize	//int src_h
					)
			) return false;
	}
	
	switch ($ext) 
	{
		case 'png':						
			return imagepng($new, $newFileName);
			break;
		case 'jpg':
			return imagejpeg($new, $newFileName, 100);
			break;
	}
}

function imageMax($ext, $fileName, $w_max, $h_max, $newFileName)
{
	switch ($ext) 
	{
		case 'png':						
			$old = imagecreatefrompng($fileName);
			if (!$old) return false;
			break;
		case 'jpg':
			$old = imagecreatefromjpeg($fileName);
			if (!$old) return false;
			break;
	}
	
	$w = (double)imagesx($old); $w_new = (double)$w;
	$h = (double)imagesy($old); $h_new = (double)$h;
	
	if ($w > $w_max)
	{
		$coef = (double)$w_max/(double)$w;
		$w_new = (double)$w_max;
		$h_new *= $coef;
	}
	
	if ($h_new > $h_max)
	{
		$coef = (double)$h_max/(double)$h_new;
		$h_new = (double)$h_max;
		$w_new *= $coef;
	}
	
	$w_new = (int)ceil($w_new);
	$h_new = (int)ceil($h_new);
	
	$new = imagecreatetruecolor($w_new, $h_new);	
	if (!imagecopyresampled($new, $old, 0, 0, 0, 0, $w_new, $h_new, $w, $h)) return false;
	
	switch ($ext) 
	{
		case 'png':						
			return imagepng($new, $newFileName);
			break;
		case 'jpg':
			return imagejpeg($new, $newFileName, 100);
			break;
	}
}

function absArray($data)
{
	$resIds = array();
	foreach ($data as $i)
	{
		$i = abs(intval($i, 10));
		if ($i) $resIds[] = $i;
	}
	return $resIds;
}

function rgbToHex($r, $g, $b)
{
	$hex = dechex($r*65536+$g*256+$b);
	while (strlen($hex) <6)
		$hex = '0'.$hex;
	return $hex;
}

function isBot()
{
	$robots = array(
					'googlebot'			,
					'nigma.ru'			,
					'facebook'			,
					//'yandexbot'			,
					//'yandexfavicons'	,
					//'yandexwebmaster'	,
					'yandex'			,
					'msnbot'			,
					'slurp'				,
					'yahoo'				,
					'askjeeves'			,
					'fastcrawler'		,
					'infoseek'			,
					'lycos'				,
					'stat.cctld.ru'		,
					'facebook'			,
					'mail.ru/'			,
					'java/'				,
					'php'				,
					'amaya'				,
					'libwww'			,
					'www-mechanize'		,
					'xenu'				,
					'dillo/'			,
					'necrawler'			,
					'netedge'			,
					'undefined'			,
					'mozilla/3.0'		,
					'search'			,
					'sparrow'			,
					'bot'
				);
	$ua = (string)trim(mb_strtolower($_SERVER['HTTP_USER_AGENT']));
	if ($ua == 'undefined' || empty($ua)) return false;
	foreach ($robots as $bot) if (strpos($ua, $bot) !== false) return true;
	return false;
}

function preventCSRF()
{
	if (sizeof($_POST))
	{
		if (empty($_SERVER['HTTP_REFERER'])) die('CSRF detected. #1');
		$ref = trim(mb_strtolower($_SERVER['HTTP_REFERER']));
		$base = trim(mb_strtolower(base_url()));

		if (strpos($ref, $base) !== 0) die('CSRF detected. #2 <br>'.$ref.'<br>'.$base);
	}
}

function getSearchElements($query)
{
	$searchElements = array();
	$searchQuery = explode(' ', $query);
	$ok = false;
	foreach ($searchQuery as $element)
	{
		$element = trim($element);
		$len = mb_strlen($element);
		if ($len) $searchElements[] = $element;				
		if ($len > 2) $ok = true;		
	}
	$searchElements = array_unique($searchElements);
	if (!$ok) return false; else return $searchElements;
}

function clearSearchStr($str)
{
	$x = preg_replace("/[^0-9^\s^A-Z^a-z^А-Я^а-я^_]/isu", " ", $str);
	return $x;
}

function clearNameStr($str)
{
	$x = preg_replace("/[^0-9^\s^A-Z^a-z^А-Я^а-я^_^\-]/isu", "", $str);
	return strip_tags(urldecode($x));
}

function searchDecode($str)
{
	$entities = array('_', '%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%3F', '%25', '%23', '%5B', '%5D');
	$replacements = array(' ', '!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "?", "%", "#", "[", "]");
	return str_replace($entities, $replacements, $str);
}

function searchEncode($str)
{
	$replacements = array('_', '%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%3F', '%25', '%23', '%5B', '%5D', '_');
	$entities = array(' ', '!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "?", "%", "#", "[", "]", '/');
	return str_replace($entities, $replacements, $str);
}

function previewDescription($str = '', $search = false, $charLimiter = 896)
{
	$str = bbToHtml($str);
	
	$str = str_ireplace(array("\r\n", "\r", "\n"), '<br>', $str);
	
	$str = str_ireplace(array(' />', '/>') , '>', $str);
	$str = str_ireplace('</p>', "</p>\r\n", $str);
	$str = str_ireplace('<br>', "\r\n", $str);
	$str = str_ireplace(array("\r\n", "\r\n ", " \r\n"), "\r\n", $str);

	if ($search) $str = strip_tags($str, '<mark>');
		else $str = strip_tags($str);

	$str = str_ireplace("\r\n", '<br>', $str);
	$str = character_limiter($str, $charLimiter);

	if ($search && substr_count($str, '<mark>') != substr_count($str, '</mark>')) 
		$str .= '</mark>';

	return $str;

}

function translitSql($table, $source = 'pTitle', $dest = 'pTitleTranslit')
{
return 
'UPDATE `'.$table.'` SET `'.$dest.'` = replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(`'.$source.'`
,"А","A")
,"Б","B")
,"В","V")
,"Г","G")
,"Д","D")
,"Е","E")
,"Ё","Yo")
,"Ж","Zh")
,"З","Z")
,"И","I")
,"Й","I")
,"К","K")
,"Л","L")
,"М","M")
,"Н","N")
,"О","O")
,"П","P")
,"Р","R")
,"С","S")
,"Т","T")
,"У","U")
,"Ф","F")
,"Х","Kh")
,"Ц","Ts")
,"Ч","Ch")
,"Ш","Sh")
,"Щ","Sch")
,"Ъ","")
,"Ы","Y")
,"Ь","")
,"Э","E")
,"Ю","Yu")
,"Я","Ya")
,"а","a")
,"б","b")
,"в","v")
,"г","g")
,"д","d")
,"е","e")
,"ё","yo")
,"ж","zh")
,"з","z")
,"и","i")
,"й","i")
,"к","k")
,"л","l")
,"м","m")
,"н","n")
,"о","o")
,"п","p")
,"р","r")
,"с","s")
,"т","t")
,"у","u")
,"ф","f")
,"х","kh")
,"ц","ts")
,"ч","ch")
,"ш","sh")
,"щ","sch")
,"ъ","")
,"ы","y")
,"ь","")
,"э","e")
,"ю","yu")
,"я","ya")
,",","_")
," ","_")
,"!","")
,"__","_")';	
}

function uploadDir()
{
 return '/usr/local/docs/wedhelper.ru/uploads/';
}

if ( ! function_exists('htmlEscape'))
{
	function htmlEscape($str, $back = false, $onlyQuotes = false)
	{
		if (!$back)
		{
			$str = str_replace('"', '&quot;', trim($str));
			$str = str_replace("'", '&prime;', trim($str));
			
			if (!$onlyQuotes)
			{
				$str = str_replace('<', '&lt;', trim($str));
				$str = str_replace('>', '&gt;', trim($str));
				$str = str_replace(':', '&#058;', trim($str));
			}
			
			$str = str_replace("\r\n\n", '<br>', trim($str));
			//$str = str_replace("\n", '<br>', trim($str));

			
		} else
		{
			$str = str_replace('<br>', "\n", trim($str));
			$str = str_replace('<br />', "\n", trim($str));
		}
		return $str;
	}
}

function addLightBox($handle)
{
	$handle->data['addingCSS'][] = 'plugins/lightbox/jquery.lightbox-0.5.css';
	$handle->data['addingJS'][] = 'plugins/lightbox/jquery.lightbox-0.5.min.js';
}

function addMarkItUp($handle)
{
	$handle->data['addingCSS'][] = 'plugins/markitup/skins/markitup/style.css';
	$handle->data['addingCSS'][] = 'plugins/markitup/sets/html/style.css';
	$handle->data['addingJS'][] = 'plugins/markitup/jquery.markitup.js';
	$handle->data['addingJS'][] = 'plugins/markitup/jquery.markitup.js';
}

function addJAlerts($handle)
{
	$handle->data['addingCSS'][] = 'css/jquery.alerts.css';
	$handle->data['addingJS'][] = 'js/jquery.alerts.js';
}

function linkJPlayerAudio()
{
	return '<script type="text/javascript" src="'.base_url().'plugins/jplayer/jquery.jplayer.min.js"></script>
			<script type="text/javascript" src="'.base_url().'plugins/jplayer/jplayer.playlist.min.js"></script>
			<link rel="stylesheet" type="text/css" href="'.base_url().'plugins/jplayer/jplayer.wedhelper.css">';
}

function urlController()
{
	$CI =& get_instance();
	return base_url().$CI->router->class.'/';
}

function controller()
{
	$CI =& get_instance();
	return $CI->router->class;
}

function UpController()
{
	$CI =& get_instance();
	return ucfirst($CI->router->class);
}

function tEssense()
{
	$CI =& get_instance();
	return 't'.ucfirst($CI->router->class);
}

function getPage($data = array(), $page = 'carcass/mainContent')
{
	return false;
	if (is_array($data))
		$data = (object)$data;
	if (empty($data->title)) $data->title = 'wedhelper';

	$CI =& get_instance();
	
	$CI->load->model('review_model', 'review');
	$data->reviewsList = $CI->review->listForMain();

	$CI->load->model('news_model', 'news');
	$data->news =  $CI->news->getLastNews();
	
  	return $CI->load->view('carcass/head', $data, true).
  			$CI->load->view('carcass/leftMenu', $data, true).
			$CI->load->view($page, $data, true).
   		$CI->load->view('carcass/footer', $data, true);
}

//----------------------------------------------------------------------
function pre($text = '')
{
	return '<pre>'.$text.'</pre>';
}

function printR($arr, $escape = true, $pre = true)
{
	$export = print_r($arr, true);
	if ($escape)
		$export = htmlEscape($export);
	if ($pre)
		$export = pre($export);
	return $export;
		
}

function diePR($arr, $escape = true, $pre = true)
{
	$arr = printR($arr, $escape, $pre);
	return die($arr);
}

function dieVD($arr)
{
	return die(var_dump($arr));
}

function dieJSON($arr)
{
	return die(json_encode($arr));
}

function utf8cut($str, $i, $escape = true)
{
	if ($escape)
		$str = htmlEscape($str);
	if (mb_strlen($str) > $i)
		$str = mb_substr($str, 0, $i);
	return trim($str);
}

function sendMail($mail, $text, $title = 'Письмо от системы "Деканат СФ БашГУ"')
{	
	$email = 'guber321@mail.ru';
	$CI =& get_instance();

	$CI->load->library('email');

	$CI->email->from($email, 'Alex');

	$CI->email->to($mail); 
	$CI->email->subject($title);
	$CI->email->message($text);	

	return $CI->email->send();
}


//----------------------------------------------------------------------

/* End of file wed_helper.php */
/* Location: ./system/helpers/wed_helper.php */